package com.xdf.xzymanagementsystem.util;

import com.xdf.xzymanagementsystem.enums.PrefixEnum;
import com.xdf.xzymanagementsystem.service.CallProcedureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * @program: xzy-management-system
 * @description: 编号生成工具类
 * @author: 张柯
 * @create: 2021-01-07 16:12
 **/
@Component
@Slf4j
public class CodeGenUtil {
    private CallProcedureService service;

    @Autowired
    public void setService(CallProcedureService service) {
        this.service = service;
    }

    /**
     * 发货计划编号生成
     *
     * @return
     * @throws Exception
     */
    public String deliveryPlanCodeGen() throws Exception {
        return service.deliveryCodeGen(PrefixEnum.DP.toString());
    }

    /**
     * 成品发货单编号生成
     *
     * @return
     */
    public String deliveryBillCodeGen() {
        return service.deliveryBillCodeGen("");
    }

    /**
     * 成品入库单编号生成
     *
     * @return
     */
    public String productCodeGen() {
        return service.productCodeGen("");
    }

    /**
     * 销售计划编号生成
     *
     * @return
     * @throws Exception
     */
    public String salesPlanCodeGen() throws Exception {
        return service.salesPlanCodeGen(PrefixEnum.FC.toString());
    }

    /**
     * 销售订单编号生成方法
     *
     * @return
     */
    public String salesOrderCodeGen() throws Exception {
        return service.salesOrderCodeGen(PrefixEnum.PO.toString());
    }


    /**
     * 单据编号生成
     *
     * @param id
     * @param size
     * @return
     */
    public String purchaseOrderCodeGen(Long id, int size) {
        return String.format("%010d", id + size);
    }
}
